(function ($) { "use strict";

    var CheckAll = function (element) {
        this.$element = $(element);
        this.options  = $.extend({}, CheckAll.DEFAULTS);
    }

    CheckAll.DEFAULTS = {}

    CheckAll.prototype.init = function () {
        var $target = $(this.$element.data('target'));

        this.$element.on('click', function(e){
            var _self = this;
            $target.each(function(){
                this.checked = _self.checked;
            });
            $('body').trigger('select-all-clicked');
        });
    };

    var old = $.fn.CheckAll;

    $.fn.CheckAll = function (option) {
        return this.each(function () {
            var c = new CheckAll(this);
            c.init();
        })
    }

    $.fn.CheckAll.Constructor = CheckAll;

    $.fn.CheckAll.noConflict = function () {
        $.fn.CheckAll = old
        return this
    }

    $(document).ready(function(){
        $('[data-toggle="checkall"]', document).CheckAll();
    });

})(window.jQuery);